<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
    $(function(){
        $("a[href='#maximize']").trigger("click");
        $("#txtTitles").bind("blur",checkTitleNewGirl);
        $("#txtName").bind("blur",checkNameNewGirl);
        $("#submitGirl").bind("click",submitGirl);
        loadNewGirl();

    });
    function submitGirl(){
        if(checkTitleNewGirl()==false)
            return;
        if(checkNameNewGirl()==false)
            return;

        /*if(checkColumnNewGirl()==false)
            return;*/

        var titles = $("#txtTitles").val();
        var txtCity = $("#txtCity").val();
        var txtName = $("#txtName").val();
        var uid = $("#txtUid").val();
        var hdidsms = $("#hdidsms").val();
        var txtVoteCount = $("#txtVoteCount").val();
        var txtIsHot = $("input[name='is_hot']:checked").val();
        var txtStatus = $("input[name='status']:checked").val();
        var txtSort = $("#txtSort").val();
        var params = {
            id:hdidsms,
            city:txtCity,
            title:titles,
            name:txtName,
            voteCount:txtVoteCount,
            uid:uid,
            is_hot:txtIsHot,
            status:txtStatus
        };

        $.ajax({
            type:"post",
            url:"admin.php/girl/addGirl",
            dataType:"json",
            data:params,
            success:function(data){
                parent.loadGirl();
                alert("提交成功");
                $("#btnCloseNewGirl").trigger("click");
            }
        });
    }


    function checkTitleNewGirl(){
        var title = $("#txtTitles").val();
        if(IsEmpty(title)){
            SetError("txtTitles","标题不能为空");
            return false;
        }
        var len = title.length;
        if(len>100){
            SetError("txtTitles","最多100字");
            return false;
        }
        SetOK("txtTitles");
        return true;
    }


    function checkNameNewGirl()
    {
        var content = $("#txtName").val();
        if(IsEmpty(content)){
            SetError("txtName","姓名不能为空");
            return false;
        }
        SetOK("txtAuthor");
        return true;
    }


    function checkUidNewGirl()
    {
        var uid = $("#txtUid").val();

        if(!IsEmpty(uid)){
            uidarr = new Array();
            uidarr = uid.split(',');
            for(var i=0;i<uidarr.length;i++){
                if(isNaN(uidarr[i])){
                    SetError('txtUid','请输入正确的格式');
                    return false;
                }
            }
        }
        SetOK('txtUid');
        return true;


    }

    function loadNewGirl(){
        var id = $("#hdidsms").val();
        if(id==0)
            return;

        //$("div.buttonActive").hide();
        $("div.button").attr("style","margin-left:260px;")
        var params = {id:id};
        $.ajax({
            type:"post",
            url:"admin.php/girl/loadNewGirl",
            dataType:"json",
            data:params,
            success:function(data){
                $("#txtTitles").val(data.title);
                $("#txtCity").val(data.city);
                $("#txtName").val(data.name);
                $("#txtUid").val(data.uid);
                $("#txtVoteCount").val(data.voteCount);

                //$("input[value="+data.is_show+"]").attr("checked",true);
            }
        });
    }
</script>
<div class="pageContent">
    <form class="pageForm required-validate">
        <div class="pageFormContent" style="; width: 98%;"
             layoutH="56">
            <table class="tableNewUser">
                <tr>
                    <td>标题：</td>
                    <td><input id="txtTitles" type="text" style="width:500px" value="" /></td>
                </tr>
                <tr>
                    <td>城市：</td>
                    <td><input id="txtCity" type="text" style="width:250px" value="" /></td>
                </tr>

                <tr>
                <tr>
                    <td>姓名：</td>
                    <td><input id="txtName" type="text" style="width:200px" value="" /></td>
                </tr>
                <tr>
                    <td>uid：</td>
                    <td><input id="txtUid" type="text" style="width:200px" value="" /><span style="margin-left:10px;">例：1,2,3</span></td>
                </tr>
                <tr>
                    <td>投票数：</td>
                    <td><input id="txtVoteCount" type="text" style="width:100px" value="" /></td>
                </tr>
                <tr>
                    <td>是否推荐：</td>
                    <td >
                        <input type="radio" value="1" name="is_hot" style="width:50px;" checked="checked">是<input style="width:50px;" type="radio" value="0" name="is_hot" />否
                    </td>
                </tr>
                <tr>
                    <td>是否显示：</td>
                    <td >
                            <input type="radio" value="1" name="status" style="width:50px;" checked="checked">显示<input style="width:50px;" type="radio" value="0" name="status" />隐藏
                    </td>
                </tr>

                <tr>
                    <td colspan="2" style='line-height: 40px'>&nbsp;&nbsp;</td>
                </tr>
            </table>
            <input type="hidden" id="hdidsms" value="<?php if(isset($_GET["id"])) print $_GET["id"]; else print 0;?>">

            <div class="buttonActive" style="width: 120px; margin-left: 180px;">
                <div class="buttonContent">
                    <button id="submitGirl" type="button" style="width: 80px">提 交</button>
                </div>
            </div>

            <div class="button" style="text-align:right">
                <div class="buttonContent" style="text-align: right">
                    <button id="btnCloseNewGirl" type="button" class="close"
                            style="width: 80px">取 消</button>
                </div>
            </div>
        </div>
    </form
</div>